﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using BluePortal.Framework;
using BluePortal.Medias.Core;

namespace BluePortal.Encoding.Core.Providers
{
    public class BaseUploadService
    {
        private string Ext(string value)
        {
            return Path.GetExtension(value);
        }

        /// <summary>
        /// get all file that not has specific extension
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        protected IEnumerable<string> GetFiles(string dir)
        {
            string[] ExcludeExtensions = new string[] { ".media", ".csproj", ".config", ".html", ".aspx", ".xml", ".zip" };
            var excludeDico = ExcludeExtensions.ToDictionary(ex => ex);

            var query = from f in Directory.GetFiles(dir)
                                       where excludeDico.ContainsKey(Ext(f)) == false
                                       select f;

            return query;
        }

        public virtual string GetUrlFromVID(Guid vid)
        {
            BCVideo bc = new BCVideo();
            bc.AddView(vid, string.Empty);
            return string.Empty;
        }

        public virtual string GetUrlFromVID(Guid vid, int formatId)
        {
            return GetUrlFromVID(vid);
        }

        protected Dictionary<string, string> ConnectionParameters = new Dictionary<string, string>();
        private string connectionString = null;
        public string ProviderOptions 
        { 
            get { return connectionString; } 
            set 
            { 
                connectionString = value; 
                ConnectionParameters.Clear();

                string[] strings = connectionString.Split(';');
                foreach (string s in strings)
                {
                    string[] s2 = s.Split('=');
                    if (s2.Length == 2) ConnectionParameters.Add(s2[0], s2[1]);
                }
            } 
        }                
    }
}
